/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edi.entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Check;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.Where;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;

/**
 *
 * @author Kamil
 */
@Entity
@Table(name = "T_DOCUMENTS")
public class DocumentEntity implements Auditable<Long, Long>, Serializable {

    private static final long serialVersionUID = 4169905761802955798L;

    @Id
    @SequenceGenerator(name = "document_sequence", sequenceName = "S_DOC_ID", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "document_sequence")
    @Column(name = "DOC_ID")
    private Long docId;

    @Column(length = 50, nullable = false, name = "DOC_NAME")
    private String docName;

    @ManyToOne()
    @JoinColumn(name = "DOC_DCT_ID", referencedColumnName = "DCT_ID", nullable = false)
    private DocTypeEntity docDctId;

    @Column(name = "DOC_CONTENT")
    private byte[] docContent;

    @ManyToOne()
    @JoinColumn(name = "DOC_LOCK_USR_ID", referencedColumnName = "USR_ID")
    private UserEntity dchLockUsrId;
    
    
    @Column(name = "DOC_AUDIT_CD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
    private DateTime createdDate;
    
    @Column(name = "DOC_AUDIT_CU")
    private Long createUser;
    
    @Column(name = "DOC_AUDIT_MD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")    
    private DateTime modifiedDate;
    
    @Column(name = "DOC_AUDIT_MU")
    private Long modifiedUser;
    
    @Column(name = "DOC_AUDIT_RD")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")   
    @SuppressWarnings("unused")
    private DateTime removeDate;
    
    @Column(name = "DOC_AUDIT_RU")
    @SuppressWarnings("unused")
    private Long removeUser;
    
    @Column(name="DOC_VERSION", columnDefinition="NUMERIC(3,1)")
    private Float fileVersion;
    
    @Column(name = "DOC_IS_FINAL", nullable = false, 
            columnDefinition="character varying(1) constraint CH_DOC_IS_FINAL check(DOC_IS_FINAL in ('0','1'))"
                    + "default '0'")
    private String isFinal;
    

    @Override
    public boolean isNew() {
        return (docId == null);
    }

    public Long getDocId() {
        return docId;
    }

    public void setDocId(Long docId) {
        this.docId = docId;
    }

    public String getDocName() {
        return docName;
    }

    public void setDocName(String docName) {
        this.docName = docName;
    }

    public DocTypeEntity getDocDctId() {
        return docDctId;
    }

    public void setDocDctId(DocTypeEntity docDctId) {
        this.docDctId = docDctId;
    }

    public byte[] getDocContent() {
        return docContent;
    }

    public void setDocContent(byte[] docContent) {
        this.docContent = docContent;
    }

    public UserEntity getDchLockUsrId() {
        return dchLockUsrId;
    }

    public void setDchLockUsrId(UserEntity dchLockUsrId) {
        this.dchLockUsrId = dchLockUsrId;
    }

     @Override
     public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
     }

     @Override
     public boolean equals(Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
     }

     @Override
     public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
     }
    

    @Override
    public Long getCreatedBy() {
      return createUser;
    }
    
    @Override
    public void setCreatedBy(Long u) {
        createUser = u;
    }

    @Override
    public org.joda.time.DateTime getCreatedDate() {
    return createdDate;
    }

    @Override
    public void setCreatedDate(org.joda.time.DateTime dt) {
       createdDate = dt;
    }

    @Override
    public Long getLastModifiedBy() {
        return modifiedUser;
    }

    @Override
    public void setLastModifiedBy(Long u) {
       modifiedUser = u;
    }

    @Override
    public org.joda.time.DateTime getLastModifiedDate() {
        return modifiedDate;
    }

    @Override
    public void setLastModifiedDate(org.joda.time.DateTime dt) {
        modifiedDate = dt;
    }
    public void setRemoveDate(org.joda.time.DateTime dt) {
        removeDate = dt;
    }

    public DateTime getRemoveDate() {
        return removeDate;
    }

    public Long getRemoveUser() {
        return removeUser;
    }

    public void setRemovedBy(Long u) {
       removeUser = u;
    }
    
    @Override
    public Long getId() {
        return docId;
    }

    public Float getFileVersion() {
        return fileVersion;
    }

    public void setFileVersion(Float fileVersion) {
        this.fileVersion = fileVersion;
    }

    public String getIsFinal() {
        return isFinal;
    }

    public void setIsFinal(String isFinal) {
        this.isFinal = isFinal;
    }

    public Long getCreateUser() {
        return createUser;
    }

    public void setCreateUser(Long createUser) {
        this.createUser = createUser;
    }

    public DateTime getModifiedDate() {
        return modifiedDate;
    }

    public void setModifiedDate(DateTime modifiedDate) {
        this.modifiedDate = modifiedDate;
    }

    public Long getModifiedUser() {
        return modifiedUser;
    }

    public void setModifiedUser(Long modifiedUser) {
        this.modifiedUser = modifiedUser;
    }

    public void setRemoveUser(Long removeUser) {
        this.removeUser = removeUser;
    }
}
